package com.ruoyi.pingjiao.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.pingjiao.domain.Evaluation;
import com.ruoyi.pingjiao.domain.query.GetPaperQueryParam;
import com.ruoyi.pingjiao.domain.vo.TeacherWithPaperVo;
import com.ruoyi.pingjiao.service.IEvaluationService;
import com.ruoyi.pingjiao.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pingjiao.domain.EvaluationPaper;
import com.ruoyi.pingjiao.service.IEvaluationPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评教问卷管理Controller
 *
 * @author ruoyi
 * @date 2022-10-22
 */
@Api("评教问卷管理")
@RestController
@RequestMapping("/pingjiao/paper")
public class EvaluationPaperController extends BaseController
{
    @Autowired
    private IEvaluationPaperService evaluationPaperService;
    @Autowired
    private IStudentService studentService;
    @Autowired
    private IEvaluationService evaluationService;

    /**
     * 查询评教问卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluationPaper evaluationPaper)
    {
        startPage();
        List<EvaluationPaper> list = evaluationPaperService.selectEvaluationPaperList(evaluationPaper);
        return getDataTable(list);
    }

    /**
     * 查询评教问卷管理列表不带分页
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:list')")
    @GetMapping("/listSimple")
    public TableDataInfo listSimple(EvaluationPaper evaluationPaper)
    {
        startPage();
        List<EvaluationPaper> list = evaluationPaperService.selectEvaluationPaperList(evaluationPaper);
        return getDataTable(list);
    }

    /**
     * 导出评教问卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:export')")
    @Log(title = "评教问卷管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluationPaper evaluationPaper)
    {
        List<EvaluationPaper> list = evaluationPaperService.selectEvaluationPaperList(evaluationPaper);
        ExcelUtil<EvaluationPaper> util = new ExcelUtil<EvaluationPaper>(EvaluationPaper.class);
        util.exportExcel(response, list, "评教问卷管理数据");
    }

    /**
     * 获取评教问卷管理详细信息
     */
    @ApiOperation("获取评教问卷详细")
    @ApiImplicitParam(name = "evaluationPaperId", value = "评教问卷ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:query')")
    @GetMapping(value = "/{evaluationPaperId}")
    public AjaxResult getInfo(@PathVariable("evaluationPaperId") Long evaluationPaperId)
    {
        return AjaxResult.success(evaluationPaperService.selectEvaluationPaperByEvaluationPaperId(evaluationPaperId));
    }

    /**
     * 获取评教问卷管理详细信息
     */
    @ApiOperation("获取评教问卷详细")
    @ApiImplicitParam(name = "evaluationPaperType", value = "评教问卷类型", required = true, dataType = "String", paramType =
            "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:get')")
    @GetMapping(value = "/type/{evaluationPaperType}")
    public AjaxResult getInfoByType(@PathVariable("evaluationPaperType") String evaluationPaperType)
    {
        return AjaxResult.success(evaluationPaperService.selectEvaluationPaperByEvaluationPaperType(evaluationPaperType));
    }



    /**
     * 新增评教问卷管理
     */


    @PreAuthorize("@ss.hasPermi('pingjiao:paper:add')")
    @Log(title = "评教问卷管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluationPaper evaluationPaper)
    {
        return toAjax(evaluationPaperService.insertEvaluationPaper(evaluationPaper));
    }

    /**
     * 修改评教问卷管理
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:edit')")
    @Log(title = "评教问卷管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluationPaper evaluationPaper)
    {
        return toAjax(evaluationPaperService.updateEvaluationPaper(evaluationPaper));
    }

    /**
     * 删除评教问卷管理
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:paper:remove')")
    @Log(title = "评教问卷管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluationPaperIds}")
    public AjaxResult remove(@PathVariable Long[] evaluationPaperIds)
    {
        return toAjax(evaluationPaperService.deleteEvaluationPaperByEvaluationPaperIds(evaluationPaperIds));
    }

//    /**
//     * 获取评价问卷详情
//     * @author hpf
//     */
//    @ApiOperation("获取评价问卷详情")
//    @ApiImplicitParams({@ApiImplicitParam(name= "teacherId", value = "教师Id", required = true, dataType = "int"),
//            @ApiImplicitParam(name= "teacherName", value = "教师姓名", required = true, dataType = "String"),
//            @ApiImplicitParam(name= "courseType", value = "课程类型", required = true, dataType = "String"),
//            @ApiImplicitParam(name= "courseclassId", value = "课程班级Id", required = true, dataType = "int"),
//            @ApiImplicitParam(name= "evaluationActivityId", value = "活动Id", required = true, dataType = "int"),
//
//    })
//    @PreAuthorize("@ss.hasPermi('pingjiao:paper:getPaperForEvalTeacher')")
//    @PostMapping(value = "/getPaper")
//    public AjaxResult getPaperForEvalTeacher(  long teacherId,String teacherName, String courseType, long courseclassId, long evaluationActivityId)
//    {
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        Long studentId = studentService.selectStudentIdByUserId(loginUser.getUserId());
//        TeacherWithPaperVo vo = evaluationPaperService.selectTeacherWithPaperVoByEvaluationPaperType( teacherId,teacherName,  courseType, courseclassId,  evaluationActivityId);
//        Map<String,Object> map =new HashMap<>();
//        map.put("teacherId",teacherId);
//        map.put("studentId",studentId);
//        map.put("courseclassId",courseclassId);
//        map.put("evaluationActivityId",evaluationActivityId);
//        float score = evaluationService.getTeacherEvaluatedScore(map);
//        vo.setScore(score);
//        return AjaxResult.success(vo);
//    }

}
